package com.cg.controller;

import com.alibaba.nacos.api.model.v2.Result;
import com.cg.client.OrderClient;
import com.cg.dto.OrderPageDto;
import com.cg.dto.PayDto;
import com.cg.dto.ResultEnum;
import com.cg.vo.PatientOrderVo;
import com.cg.vo.PayOrderVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (Order)表控制层
 *
 * @author chengong
 * @since 2024-01-14 17:00:58
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    /**
     * 服务对象
     */
    @Resource
    private OrderClient orderClient;

    /**
     * 预约信息列表
     */
    @PostMapping("/queryOrderList")
    public Result<Map<String,Object>> queryOrderList(OrderPageDto orderPageDto){
        return orderClient.queryOrderList(orderPageDto);
    }

    /**
     * 获取患者信息及其预约信息
     */
    @PostMapping("/queryPatientOrder")
    public Result<PatientOrderVo> queryPatientOrder(OrderPageDto orderPageDto){
        return orderClient.queryPatientOrder(orderPageDto);
    }


    /**
     * 取号前查询订单支付方式
     */
    @GetMapping("/getPayOrderByOrderNum")
    public Result<PayOrderVo> getPayOrderByOrderNum(String orderNum){
        return orderClient.getPayOrderByOrderNum(orderNum);
    }

    /**
     * 去支付
     */
    @GetMapping("/toPay")
    public String toPay(PayDto payDto){
        Result<String> stringResult = orderClient.toPay(payDto);
        if(stringResult.getCode().equals(ResultEnum.SUCCESS.getCode())){
            System.out.println("失败");
            return stringResult.getMessage();
        }
        System.out.println(stringResult.getData());
        return stringResult.getData();
    }

}

